package com.tencent.bugly.beta.download;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import com.jxw.launcher.util.ReceiverUtil;
import com.tencent.bugly.beta.global.e;
import com.tencent.bugly.beta.ui.f;
import com.tencent.bugly.beta.ui.g;
import com.tencent.bugly.beta.ui.h;
import com.tencent.bugly.proguard.am;
import com.tencent.bugly.proguard.an;
import java.util.concurrent.ConcurrentHashMap;

/* compiled from: BUGLY */
/* loaded from: classes.dex */
public class BetaReceiver extends BroadcastReceiver {
    public static ConcurrentHashMap<String, c> netListeners = new ConcurrentHashMap<>(3);
    public static int netStatus = 0;
    public static String CONNECTIVITY_CHANGE = ReceiverUtil.ACTION_CONNECTIVITY_ACTION;

    public static synchronized void addTask(DownloadTask downloadTask) {
        synchronized (BetaReceiver.class) {
            netStatus = com.tencent.bugly.beta.global.a.a(e.E.s);
            f fVar = new f();
            fVar.n = downloadTask;
            netListeners.put(downloadTask.getDownloadUrl(), new c(2, downloadTask, false, fVar));
        }
    }

    @Override // android.content.BroadcastReceiver
    public synchronized void onReceive(final Context context, final Intent intent) {
        am.a().a(new Runnable() { // from class: com.tencent.bugly.beta.download.BetaReceiver.1
            @Override // java.lang.Runnable
            public void run() {
                try {
                    if (intent.getAction().equals(BetaReceiver.CONNECTIVITY_CHANGE)) {
                        int i = BetaReceiver.netStatus;
                        BetaReceiver.netStatus = com.tencent.bugly.beta.global.a.a(context);
                        for (c cVar : BetaReceiver.netListeners.values()) {
                            cVar.a(i, BetaReceiver.netStatus);
                        }
                    } else if (intent.getAction().equals(com.tencent.bugly.beta.ui.c.a.c)) {
                        int intExtra = intent.getIntExtra("request", -1);
                        if (intExtra != 1) {
                            if (intExtra == 2) {
                                g.a(com.tencent.bugly.beta.ui.c.a.e, true, true, 0L);
                                return;
                            } else {
                                Log.v("", "do nothing");
                                return;
                            }
                        }
                        DownloadTask downloadTask = com.tencent.bugly.beta.ui.c.a.b;
                        if (downloadTask == null) {
                            return;
                        }
                        int status = downloadTask.getStatus();
                        if (status != 0) {
                            if (status == 1) {
                                com.tencent.bugly.beta.global.a.a(e.E.s, downloadTask.getSaveFile(), downloadTask.getMD5());
                            } else if (status == 2) {
                                BetaReceiver.netListeners.remove(downloadTask.getDownloadUrl());
                                downloadTask.stop();
                            } else if (status != 3 && status != 4 && status != 5) {
                            }
                            if (com.tencent.bugly.beta.upgrade.c.a.e == null || h.v == null) {
                            }
                            h.v.a(downloadTask);
                            return;
                        }
                        BetaReceiver.addTask(downloadTask);
                        downloadTask.download();
                        if (com.tencent.bugly.beta.upgrade.c.a.e == null) {
                        }
                    }
                } catch (Exception e) {
                    if (an.b(e)) {
                        return;
                    }
                    e.printStackTrace();
                }
            }
        });
    }
}
